package org.klarton.filter.goertzel;

import org.klarton.filter.FilterBank;

/**
 * This factory creates a bank full of {@link GoertzelFilter}s.
 */
public class GoertzelFilterBankFactory {

    private static final String[] notes = new String[]{"c","c#/db","d","d#/eb","e","f","f#/gb","g","g#/ab","a","a#/bb","b"};

    public static FilterBank createFilterBank(double a4Frequency, double sampleRate) {
        FilterBank bank = new FilterBank();
        for (int n = 18; n <= 71; n++) {
            final double frequency = a4Frequency * Math.pow(2, ((double)(n-49))/12);
            final double prevFrequency = a4Frequency * Math.pow(2, ((double)(n-50))/12);
            String name = notes[(n-4)%12] + n/12;
            bank.addFilter(new GoertzelFilter(name, frequency, sampleRate, frequency - prevFrequency));
        }

        return bank;
    }
}
